import { reqGetGoodDetailInfoData } from '@/api'

const state = {
    goodInfo:{}
}
const actions = {
  async getGoodDetailInfoData({ commit }, id) {
    const result = await reqGetGoodDetailInfoData(id)
    if (result.code === 200) {
        console.log(result.data);
      commit('SAVE_GOOD_DETAIL_INFO_DATA',result.data)
    } else {
      console.log(result.message);
    }
  }
}
const mutations = {
  SAVE_GOOD_DETAIL_INFO_DATA(state,payload) {
    state.goodInfo = payload // 是个对象形式
  }
}
const getters = {
    categoryView(state) {
        return state.goodInfo.categoryView || {}
        },
        skuInfo(state) {
        return state.goodInfo.skuInfo || {}
        },
        spuSaleAttrList(state) {
        return state.goodInfo.spuSaleAttrList || []
      }
  }

export default {
  namespaced: true, // 开启命名空间
  state,
  actions,
  mutations,
  getters
}